import { AssetInfoApi } from "@/api/erp/property/assetInfo";
import { PropertyTypeApi } from "@/api/erp/property/assetType";
import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useRender, useTable } from "@/components/Table";
import { Tag } from "antd";
import "./index.less";
import { useTranslation } from "react-i18next";
const newAdd = (props: any) => {
	const en_vi = "drugStorage.property";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.asmName`),
			component: "Input",
			field: "asmName"
		},
		{
			label: t(`${en_vi}.asmType`),
			component: "ApiSelect",
			field: "asmType",
			componentProps: {
				api: PropertyTypeApi.getPropertyTypePage,
				labelField: "name",
				valueField: "id",
				immediate: false
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.asmId`),
			dataIndex: "asmId"
		},
		{
			title: t(`${en_vi}.asmName`),
			dataIndex: "asmName"
		},
		{
			title: t(`${en_vi}.asmType`),
			dataIndex: "asmType"
		},
		{
			title: t(`${en_vi}.sqNumb`),
			dataIndex: "sqNumb"
		},
		{
			title: t("felix_ui.createdTime"),
			dataIndex: "createdTime",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`drugStorage.createdBy`),
			dataIndex: "createdBy"
		},
		{
			title: t("felix_ui.status"),
			dataIndex: "status",
			render: (_, { status }) => (
				<>{status == "0" ? <Tag color="success">{t(`felix_ui.open`)}</Tag> : <Tag color="error">{t(`felix_ui.close`)}</Tag>}</>
			)
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: AssetInfoApi.getAssetInfoPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 8 },
			actionColOptions: { span: 8 }
		},
		bordered: true,
		useSearchForm: true
	});
	const handleSubmit = async () => {
		const orderItem = getSelectRows();
		props.setOrderItem(orderItem[0]?.asmId);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
